#include "types.h"
#include <iostream>
#include "algorithm.h"

using namespace std;

void ReadIncomingData(IncomingData& incData)
{
}



void PrintResultData(const ResultData& resultData)
{
	ResultData::const_reverse_iterator itGroup(resultData.end());
	ResultData::const_reverse_iterator itEnd(resultData.begin());
	for ( ; itGroup != itEnd;  ++itGroup)
	{
		int iBlockLength = itGroup->first;
		cout << "Length: " << iBlockLength << endl;

		GroupOfBlocks::const_iterator itGroupOfBlocks = itGroup->second.begin();
		GroupOfBlocks::const_iterator itGroupOfBlocksEnd = itGroup->second.end();
		for ( ; itGroupOfBlocks != itGroupOfBlocksEnd; ++itGroupOfBlocks)
		{
			EqualBlocks::const_iterator itEqBlocks = itGroupOfBlocks->begin();
			EqualBlocks::const_iterator itEqBlocksEnd = itGroupOfBlocks->end();
			for ( ; itEqBlocks != itEqBlocksEnd; ++itEqBlocks)
			{
				cout << "Filename: " << itEqBlocks->first << ". ";
				cout << "Between lines " << itEqBlocks->second << " and " << itEqBlocks->second + iBlockLength - 1;
				cout << endl;
			}
			cout << endl;
		}
		cout << endl;
	}
}


#ifndef RUN_TEST


int main(int argc, char* argv[])
{
	IncomingData	incData;
	ResultData		resultData;

	std::cout << "Processing..." << std::endl;

	//	start timer

	ReadIncomingData(incData);

	//Algo::FindEqualBlocks(incData, resultData);		//	for release
	Algo::TestFindEqualBlocks(incData, resultData);		//	for test only
	
	//	end timer

	PrintResultData(resultData);
	
	return 0;
}
#else

#include "tests/cppunit/cppunit_proxy.h"
#include "tests/cppunit/file_reporter.h"


namespace CPPUNIT_NS
{
	int CPPUNIT_NS::TestCase::m_numErrors = 0;
	int CPPUNIT_NS::TestCase::m_numTests = 0;

	CPPUNIT_NS::TestCase *CPPUNIT_NS::TestCase::m_root = 0;
	CPPUNIT_NS::Reporter *CPPUNIT_NS::TestCase::m_reporter = 0;

	void CPPUNIT_NS::TestCase::registerTestCase(TestCase *in_testCase)
	{
		in_testCase->m_next = m_root;
		m_root = in_testCase;
	}

	int CPPUNIT_NS::TestCase::run(Reporter *in_reporter, const char *in_testName, bool invert)
	{
		TestCase::m_reporter = in_reporter;

		m_numErrors = 0;
		m_numTests = 0;

		TestCase *tmp = m_root;
		while (tmp != 0)
		{
			tmp->myRun(in_testName, invert);
			tmp = tmp->m_next;
		}
		return m_numErrors;
	}
}


int main(int argc, char* argv[])
{
	char *fileName = 0;
	char *testName = "";
	char *xtestName = "";
	bool doMonitoring = false;

	CPPUNIT_NS::Reporter* reporter;

	if (fileName != 0)
		reporter = new FileReporter(fileName, doMonitoring);
	else
		reporter = new FileReporter(stdout, doMonitoring);

	int num_errors;

	if (xtestName[0] != 0)
		num_errors = CPPUNIT_NS::TestCase::run(reporter, xtestName, true);
	else
		num_errors = CPPUNIT_NS::TestCase::run(reporter, testName);

	reporter->printSummary();
	delete reporter;

	return num_errors;
}

#endif
